$(function () {
    var path = window.location.href;//获取传过来的地址路径
    var id = path.substr(path.lastIndexOf("=") + 1);//截取路径获取传值编号
    showDetail(id);
});

function showDetail(id) {
    $.ajax({
        url:urlPlatfrom+"hotel/hotelDetail",
        data:{"id": id},
        type:"get",
        headers:{"token":sessionStorage.getItem("token")},
        success:function (data) {
			console.log(data);
            if (data.success){
                showData(data.data);
            }
			else{
                location.href="../../login.html";
            }
        }
    });
}

function showData(data) {
    $(".detail-crumb_hotel").html(data.hotel.hotelName);
    $(".detail-headline_name").html(data.hotel.hotelName);
    $(".detail-crumb_item").html(data.hotel.redundantCityName+"酒店");
	$(".detail-headline_position_text").html(data.hotel.address);
	$(".detail-headline_desc_text").html(data.hotel.details);
	$(".detail-headline_desc_text").css({"width":"270px","overflow":"hidden"});
    for (var i = 0; i < data.images.length; i++) {
        if (data.images[i].type=="0" && data.images[i].position==1){
            $(".detail-headalbum_bigpicImg").attr("src",data.images[i].imgUrl);
        }
        if (data.images[i].type=="1"){
			 if($(".detail-headalbum_item").length<6){
				 var detailSmallPicture = `<div class="detail-headalbum_item">
				 <div class="m-img " style="width:100%;height:100%">
				 <div class="preload"><img src='`+data.images[i].imgURL+`' /></div></div>
				 </div>`;
				 $(".detail-headalbum_childbox").append(detailSmallPicture);
			 }
        }
    }
	var score = 0.0;
	var positionScore = 0.0;
	var hygieneScore = 0.0;
	var serviceScore = 0.0;
	var facilitiesScore = 0.0;
	var commentCount = 0;
	if(data.hotelComment.length>0 && data.hotelComment != ""){
		for (var i = 0; i < data.hotelComment.length; i++) {
			alert("+");
			score += data.hotelComment[i].score;
			positionScore += data.hotelComment[i].positionScore;
			hygieneScore += data.hotelComment[i].hygieneScore;
			serviceScore += data.hotelComment[i].serviceScore;
			facilitiesScore += data.hotelComment[i].facilitiesScore;
		}
		score = score / data.hotelComment.length;
		positionScore = positionScore / data.hotelComment.length;
		hygieneScore = hygieneScore / data.hotelComment.length;
		serviceScore = serviceScore / data.hotelComment.length;
		facilitiesScore = facilitiesScore / data.hotelComment.length;
		commentCount = data.hotelComment.length;
	}
	$(".detail-headreview_score_value").html(score.toFixed(1));
	$(".commentCount").html(commentCount.toFixed(1));
	$(".positionScore").html(positionScore.toFixed(1));
	$(".hygieneScore").html(hygieneScore.toFixed(1));
	$(".serviceScore").html(serviceScore.toFixed(1));
	$(".facilitiesScore").html(facilitiesScore.toFixed(1));
}